.PHONY:all

prefix = /usr
top_builddir = target/debug
bindir = /usr/bin
sbindir = /usr/sbin
libexecdir = /usr/libexec
datarootdir = $(prefix)/share


all:
	cd variadic && make 
	cargo build

install:
	mkdir -p $(DESTDIR)$(bindir)
	mkdir -p $(DESTDIR)$(sbindir)
	mkdir -p $(DESTDIR)$(libexecdir)/utsudo
	mkdir -p $(DESTDIR)/usr/lib/tmpfiles.d
	mkdir -p $(DESTDIR)$(datarootdir)/licenses/utsudo
	mkdir -p $(DESTDIR)/usr/share/locale/utsudo/translations/en-US
	mkdir -p $(DESTDIR)/usr/share/locale/utsudo/translations/zh-CN
	mkdir -p $(DESTDIR)/usr/share/locale/utsudo/translations/zh-HK
	install -m 0755 $(top_builddir)/libgroup_file.so $(DESTDIR)$(libexecdir)/utsudo/group_file.so
	install -m 0755 $(top_builddir)/libsample_plugin.so $(DESTDIR)$(libexecdir)/utsudo/sample_plugin.so
	install -m 0755 $(top_builddir)/libsystem_group.so $(DESTDIR)$(libexecdir)/utsudo/system_group.so
	install -m 0755 $(top_builddir)/libutsudo_noexec.so $(DESTDIR)$(libexecdir)/utsudo/utsudo_noexec.so
	install -m 0755 $(top_builddir)/libutsudoers.so $(DESTDIR)$(libexecdir)/utsudo/utsudoers.so
	install -m 0755 $(top_builddir)/libutsudo_util.so $(DESTDIR)$(libexecdir)/utsudo/libutsudo_util.so
	install -m 0755 variadic/libplugins_variadic.so $(DESTDIR)$(libexecdir)/utsudo/libplugins_variadic.so
	install -m 0755 variadic/libutil_variadic.so $(DESTDIR)$(libexecdir)/utsudo/libutil_variadic.so
	install -m 0755 $(top_builddir)/utsesh $(DESTDIR)$(libexecdir)/utsudo/utsesh
	install -m 0755 $(top_builddir)/cvtutsudoers  $(DESTDIR)$(bindir)/cvtutsudoers
	install -m 0755 $(top_builddir)/utsudo $(DESTDIR)$(bindir)/utsudo
	install -m 0755 $(top_builddir)/utsudoreplay $(DESTDIR)$(bindir)/utsudoreplay
	install -m 0755 $(top_builddir)/viutsudo $(DESTDIR)$(sbindir)/viutsudo
	rm -f $(DESTDIR)$(bindir)/utsudoedit
	cd $(top_builddir) && ln -s utsudo $(DESTDIR)$(bindir)/utsudoedit
	install -m 0755 init.d/utsudo.conf $(DESTDIR)/usr/lib/tmpfiles.d/utsudo.conf
	install -m 0755 LICENSE $(DESTDIR)$(datarootdir)/licenses/utsudo/LICENSE
	install -m 0755 translations/en-US/message.ftl $(DESTDIR)/usr/share/locale/utsudo/translations/en-US/
	install -m 0755 translations/zh-CN/message.ftl $(DESTDIR)/usr/share/locale/utsudo/translations/zh-CN/
	install -m 0755 translations/zh-HK/message.ftl $(DESTDIR)/usr/share/locale/utsudo/translations/zh-HK/


.PHONY:clean
clean:
	cd variadic && make clean
	cargo clean
